package com.yf.controller.admin.article;

import java.util.List;
import java.util.Map;

import com.yf.vo.CampaignBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.entity.CampaignEntity;
import com.yf.service.article.CampaignService;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 活动Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Aug 22 14:30:08 CST 2018
 */
@RestController
@RequestMapping("/campaign")
public class CampaignController {
    @Autowired
    private CampaignService campaignService;

    /**
     * 列表活动
     */
    @RequestMapping("/list")
    @RequiresPermissions("campaign:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CampaignEntity> campaignList = campaignService.queryList(params);
        return R.ok(new PageInfo(campaignList));
    }

    /**
     * 查看活动
     */
    @SysLog("查看活动")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("campaign:info")
    public R info(@PathVariable("id") Long id) {
        CampaignEntity campaign = campaignService.get(id);

        return R.ok(campaign);
    }

    /**
     * 保存活动
     */
    @SysLog("保存活动")
    @RequestMapping("/save")
    @RequiresPermissions("campaign:save")
    public R save(CampaignEntity campaign) {
        campaignService.save(campaign);

        return R.ok(campaign);
    }

    /**
     * 修改活动
     */
    @SysLog("修改活动")
    @RequestMapping("/update")
    @RequiresPermissions("campaign:update")
    public R update(CampaignEntity campaign) {
        campaignService.update(campaign);

        return R.ok(campaign);
    }

    /**
     * 删除活动
     */
    @SysLog("删除活动")
    @RequestMapping("/delete")
    @RequiresPermissions("campaign:delete")
    public R delete(@RequestBody Long[]ids) {
        campaignService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有活动
     */
    @SysLog("所有活动")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<CampaignEntity> campaignList = campaignService.queryList(params);

        return R.ok(campaignList);
    }

    /***********自定义开始***********/

    /**
     * back 根据活动名称查询当前活动的参与人
     */
    @RequestMapping("/title")
    public R getCampaignList() {
        List<CampaignBackVo> list = campaignService.campaignList();
        return R.ok(list);
    }

    /**
     * back 活动参与者信息
     * @return
     */
    @RequestMapping("/campaignInfo")
    public R getCampaignVoList(@RequestParam Map<String, Object> params){
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CampaignBackVo> list = campaignService.campaignVoList(params);
        return R.ok(new PageInfo(list));
    }

}
